//
//  HAODE
//
//  Created by panquanReabam.com on 15/9/23.
//  Copyright (c) 2015年 reabam.com. All rights reserved.
//

#import "BusinessPurchaseReturnAddViewController.h"
#import "ZJSwitch.h"
#import "HAODEsingleton.h"
#import "UIViewExt.h"
#import "HttpRequest.h"
#import "JSONKit.h"
#import "UIImageView+WebCache.h"
#import "daogouview.h"
#import "RDVTabBarController.h"
#import "MJRefresh.h"
#import "shopcatCell.h"
#import "huiyuandengjiViewController.h"
#import "shangpingview.h"
#import "peisongleibieViewController.h"
#import "ToResiduePayViewController.h"
#import "addhuiyuanViewController.h"
#import "huiyuanDetailsViewController.h"
#import "BusinessCouponDetailViewController.h"
#import "saoyisaoViewController.h"
#import "BusinessMemberAddressViewController.h"
#import "BusinessWhsWhsItemListViewController.h"
#import "PlatformProductTypeListViewController.h"
#import "BusinessSupplierSupplierListViewController.h"
#import "BusinessPOrderListViewController.h"
#import "BusinessPurchaseReturnListViewController.h"
@interface BusinessPurchaseReturnAddViewController ()<MBProgressHUDDelegate,UIGestureRecognizerDelegate,UINavigationControllerDelegate,UITextFieldDelegate,UITextViewDelegate,UISearchBarDelegate,UIScrollViewDelegate>

@property (strong, nonatomic) NSString*GuideCode;
@property (strong, nonatomic) NSString*whsInTypeCode;
@property (strong, nonatomic) NSString*whsId;
@property (strong, nonatomic) NSString*WhsInType;
@property(nonatomic,retain)UIDatePicker* da;

@end

@implementation BusinessPurchaseReturnAddViewController

{
    UISearchBar *search;
    HAODEsingleton* commdity;
    UIButton* sxBtn;
    UIButton*jiantouBtn;
    UIButton*cardBtn;
    float lastContentOffset;
    UITextField*searchTextField;
    UITextField*zhekoujineTextFied;
    UITextField*songhuoTextFied;
    UITextField*anzhuangTextFied;
    UIButton*daogouname;
    daogouview*daogouView;
    UIButton*leixingBtn;
    UIButton*leixingBtn1;
    UIView*view;
    UIView*view1;
    shangpingview*shangpingView;
    UIScrollView*mainScroll;
    UIScrollView*MYmainScroll;
    UILabel*huiyuanname;
    UIButton *tureBtn;
    UILabel*dingdanhao1;
    BOOL saveAccount;
    UIButton *xuanze;
    UIButton*jiagemingxi1;
    UIButton*DiscountRateSatBtn;
    NSMutableArray* arrrss;
    NSMutableArray* arrrss1;
    NSMutableArray*DiscountRatecode ;
    NSMutableArray*DiscountRatecontent ;
    ZJSwitch *switch2;
    UITextField*dinjinjineTextFied;
    UIButton*EarnestRateSatBtn;
    UILabel* weightke;
    UIView*view2;
    UIView*view3;
    UIView*view4;
    UIView*view5;
    UIView*view6;
    UITextView* tv;
    UILabel * label;
    UIImageView*imagess;
    UILabel*shengyuzhifujiage1;
    UIButton*anzhuangSatBtn;
    UIButton*peisongSatBtn;
    UIView* myToolBar;
    UIButton*hejiMoney;
    NSMutableArray* codearr;
    NSMutableArray* contenarrr;
    NSMutableArray*dealPrice;
    NSMutableArray*headImage;
    NSMutableArray*itemId;
    NSMutableArray*itemName;
    NSMutableArray*quantity;
    NSMutableArray*salePrice;
    NSMutableArray*specId;
    NSMutableArray* specName;
    NSMutableArray* specPrice;
    NSMutableArray* returnQty;
    NSMutableArray*porderItemId;
    NSMutableArray*itemType;
    UIButton*hejibuyBtn1;
    NSMutableArray *xiugaishuliangArray;
    
    NSMutableArray *selectFeatureCodeArray;
    NSMutableArray *orderItemIds;
    NSMutableArray *selectimageArray;
    NSMutableArray *selectshuliangArray;
    NSMutableArray *selectduoshaoArray;
    NSMutableArray *keyishopCartIds;
    UITableView *table_list;
    NSMutableArray *keyidealPrice;
    NSMutableArray *keyiitemCode;
    NSMutableArray *keyiitemName;
    NSMutableArray *keyiheadImage;
    NSMutableArray *keyispecName;
    NSMutableArray *keyiquantity;
    NSMutableArray * deliveryStatus;
    NSMutableArray *porderItemIdArray;
    NSMutableArray *selectitemCodeArray;
    NSMutableArray * itemCode;
    UIButton*xiugaiview;
    UILabel*shu;
    UITextField*jiageTextFied;
    UIView*toumingtu;
}
@synthesize alt = alt;

-(void)BackAction:(UIButton *)sender{
    
    [self.navigationController popViewControllerAnimated:YES];
    
}
- (void)viewDidDisappear:(BOOL)animated

{
    
    [super viewDidDisappear:animated];
    
    
    
    self.navigationController.delegate = nil;
    
}
-(void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    
    [[self rdv_tabBarController] setTabBarHidden:YES];
    self.navigationController.navigationBarHidden=NO;
        self.navigationController.navigationBar.barStyle = UIBaselineAdjustmentNone;
    UILabel *lineLabel=[[UILabel alloc] initWithFrame:CGRectMake(0, 43,ScreenWidth, 1)];
    [lineLabel setBackgroundColor:[UIColor colorWithRed:238.0/255.0 green:238.0/255.0 blue:238.0/255.0 alpha:1.0]];
    [self.navigationController.navigationBar addSubview:lineLabel];
    [self.navigationController.navigationBar setTintColor:[UIColor whiteColor]];
    [[UINavigationBar appearance] setBarTintColor:Color];
    
    UIImage* backImage = [UIImage imageNamed:@"fanhui"];
    CGRect backframe = CGRectMake(0,0,30,30);
    UIButton* backButton= [[UIButton alloc] initWithFrame:backframe];
    [backButton setBackgroundImage:backImage forState:UIControlStateNormal];
    backButton.titleLabel.textAlignment=NSTextAlignmentLeft;
    [backButton addTarget:self action:@selector(BackAction:) forControlEvents:UIControlEventTouchUpInside];
    UIBarButtonItem* leftBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:backButton];
    self.navigationItem.leftBarButtonItem = leftBarButtonItem;
    self.navigationController.delegate = self;
    
    self.navigationController.interactivePopGestureRecognizer.delegate = self;
    [self.navigationController.navigationBar setBackgroundImage:[UIImage imageNamed:@""] forBarMetrics:UIBarMetricsDefault];
    self.navigationController.navigationBar.shadowImage =[[UIImage alloc] init];
    //会员信息
    
    self.title = self.titleName;
    [self.navigationController.navigationBar setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:
                                                                     backColor,
                                                                     UITextAttributeTextColor,
                                                                     [UIColor colorWithRed:0.0 green:0.0 blue:0.0 alpha:1],
                                                                     UITextAttributeTextShadowColor,
                                                                     [NSValue valueWithUIOffset:UIOffsetMake(0, 0)],
                                                                     UITextAttributeTextShadowOffset,
                                                                     [UIFont fontWithName:@"Helvetica Neue" size:tetlefot],
                                                                     UITextAttributeFont,nil]];
    
//    
//    leixingBtn.titleLabel.text=commdity.userName;
//    self.whsId=commdity.actTypeCode;
//    leixingBtn1.titleLabel.text=commdity.content1;
//    
    
}



- (void)dateChanged:(id)sender
{
    
    UIDatePicker* picker = (UIDatePicker*)sender;
    NSDateFormatter* df = [[NSDateFormatter alloc] init];
    [df setDateFormat:@"yyyy-MM-dd "];
    
    
    anzhuangTextFied.text = [NSString stringWithFormat:@"%@", [df stringFromDate:picker.date]];
    
    
}






- (void)viewDidLoad
{
    
    [super viewDidLoad];
    
    _da = [[UIDatePicker alloc] init];
    [_da addTarget:self action:@selector(dateChanged:) forControlEvents:UIControlEventValueChanged];
    _da.datePickerMode = UIDatePickerModeDateAndTime;
    _da.backgroundColor=[UIColor whiteColor];
    
    commdity=[HAODEsingleton shared];
    
    
    myToolBar=[[UIView alloc]initWithFrame:CGRectMake(0, 0, ScreenWidth, viewheight)];
    myToolBar.backgroundColor=jianpancolor;
    UIButton*  tubtnDone=[[UIButton alloc]initWithFrame:CGRectMake(logoX,logoY, logoheight, logowidth)];
    [tubtnDone setImage:[UIImage imageNamed:@""] forState:UIControlStateNormal];
    [tubtnDone addTarget:self action:@selector(OnTapDone) forControlEvents:UIControlEventTouchUpInside];
    [myToolBar addSubview:tubtnDone];
    UIButton*btnDone111=[[UIButton alloc]initWithFrame:CGRectMake(myToolBar.frame.size.width - 55, 12, 40, 16)];
    [btnDone111 setTitle:@"确定" forState:UIControlStateNormal];
    [btnDone111 setTitleColor:jianpancolor1 forState:UIControlStateNormal];
    btnDone111 .titleLabel .font=[UIFont systemFontOfSize:daxiao];
    [btnDone111 addTarget:self action:@selector(OnTapDone) forControlEvents:UIControlEventTouchUpInside];
    [myToolBar addSubview:btnDone111];
    myToolBar.alpha=alp;
    UIButton* dabtn=[[UIButton alloc]initWithFrame:CGRectMake(myToolBar.frame.size.width-60, 0, 60, 40)];
    [dabtn addTarget:self action:@selector(OnTapDone) forControlEvents:UIControlEventTouchUpInside];
    [myToolBar addSubview:dabtn];
    
    
    view=[[UIView alloc]initWithFrame:CGRectMake(0, 64, ScreenWidth, 535/2-45)];
    view.backgroundColor=zuiqianhuicolor;
    view.layer.borderWidth = 0.35;
    view.layer.borderColor = qianhuicolor.CGColor;
    
    view1=[[UIView alloc]initWithFrame:CGRectMake(0, 0, ScreenWidth, 140/2)];
    view1.backgroundColor=[UIColor whiteColor];
    [view addSubview:view1];
    
    
    
    
    view2=[[UIView alloc]initWithFrame:CGRectMake(0, view1.bottom+10, ScreenWidth,265/2-45)];
    view2.backgroundColor=[UIColor whiteColor];
    view2.layer.borderWidth = 0.35;
    view2.layer.borderColor = qianhuicolor.CGColor;
    [view addSubview:view2];
    
    UILabel *line3=[[UILabel alloc] initWithFrame:CGRectMake(15,  175/2/2, ScreenWidth-30, 0.35)];
    line3.backgroundColor=qianhuicolor;
    [view2 addSubview:line3];
    
    UILabel*leixing=[[UILabel alloc]initWithFrame:CGRectMake(15,0, 200, 175/2/2)];
    leixing.text=@"供应商";
    leixing.textColor=zhonghuiColor;
    leixing.font=[UIFont systemFontOfSize:conten14fot];
    [view2 addSubview:leixing];
    
    
    leixingBtn=[[UIButton alloc]initWithFrame:CGRectMake(50,  0, ScreenWidth-100,175/2/2)];
    leixingBtn.titleLabel.font=[UIFont systemFontOfSize:conten14fot];
    [leixingBtn setTitle:@"                                                             " forState:UIControlStateNormal];
    
    leixingBtn.contentHorizontalAlignment=UIControlContentHorizontalAlignmentRight;
//    [leixingBtn addTarget:self action:@selector(xuanzhidaogou:) forControlEvents:UIControlEventTouchUpInside];
    [leixingBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    [view2 addSubview:leixingBtn];
    
    UIButton*jiantouBtn12 = [[UIButton alloc] initWithFrame:CGRectMake(ScreenWidth-35,15,8, 13)];    [jiantouBtn12 setImage:[UIImage imageNamed:@"xiangzuo-.png"] forState:UIControlStateNormal];
//    [jiantouBtn12 addTarget:self action:@selector(xuanzhidaogou:) forControlEvents:UIControlEventTouchUpInside];
//    [view2 addSubview:jiantouBtn12];
    
    
    
    
    UILabel*leixing1=[[UILabel alloc]initWithFrame:CGRectMake(15,175/2/2, 200, 175/2/2)];
    leixing1.text=@"仓库";
    leixing1.textColor=zhonghuiColor;
    leixing1.font=[UIFont systemFontOfSize:conten14fot];
    [view2 addSubview:leixing1];
    
    leixingBtn1=[[UIButton alloc]initWithFrame:CGRectMake(50,  175/2/2, ScreenWidth-100,175/2/2)];
    [leixingBtn1 setTitle:@"                                                             " forState:UIControlStateNormal];
    leixingBtn1.titleLabel.font=[UIFont systemFontOfSize:conten14fot];
    leixingBtn1.contentHorizontalAlignment=UIControlContentHorizontalAlignmentRight;
//    [leixingBtn1 addTarget:self action:@selector(xuanzhidaogou1:) forControlEvents:UIControlEventTouchUpInside];
    [leixingBtn1 setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    [view2 addSubview:leixingBtn1];
    
    UIButton*jiantouBtn121 = [[UIButton alloc] initWithFrame:CGRectMake(ScreenWidth-35,175/2/2+15,8, 13)];
    [jiantouBtn121 setImage:[UIImage imageNamed:@"xiangzuo-.png"] forState:UIControlStateNormal];
//    [jiantouBtn121 addTarget:self action:@selector(xuanzhidaogou1:) forControlEvents:UIControlEventTouchUpInside];
//    [view2 addSubview:jiantouBtn121];
    
    
    
    
    
    
//    UILabel*songhuo=[[UILabel alloc]initWithFrame:CGRectMake(15, 175/2/2+45, 80, 175/2/2)];
//    songhuo.text=@"退货时间";
//    songhuo.textColor=shenhuicolor;
//    songhuo.font=[UIFont systemFontOfSize:14];
//    [view2 addSubview:songhuo];
//    
//    
//    anzhuangTextFied=[[UITextField alloc]initWithFrame:CGRectMake(100,  175/2/2+44, ScreenWidth-140,  175/2/2)];
//    anzhuangTextFied.borderStyle = UITextBorderStyleNone;
//    anzhuangTextFied.font = [UIFont systemFontOfSize: contenfot];
//    anzhuangTextFied.textColor=luseColor;
//    anzhuangTextFied.autocapitalizationType = UITextAutocapitalizationTypeSentences;
//    anzhuangTextFied.tag=4;
//    anzhuangTextFied.placeholder = @"请选择退货时间"; //默认显示的字
//    anzhuangTextFied.delegate = self;
//    anzhuangTextFied.textAlignment=NSTextAlignmentRight;
//    [anzhuangTextFied setUserInteractionEnabled:YES];
//    anzhuangTextFied.clearButtonMode = UITextFieldViewModeWhileEditing;
//    [view2 addSubview:anzhuangTextFied];
//    anzhuangTextFied.inputAccessoryView = myToolBar;
//    
//    UIButton *jiantouBtn3 = [[UIButton alloc] initWithFrame:CGRectMake(ScreenWidth-35,175/2/2+45+16,46/3, 25/3)];
//    [jiantouBtn3 setImage:[UIImage imageNamed:@"xiangxia-"] forState:UIControlStateNormal];
//    //              [jiantouBtn3 addTarget:self action:@selector(anzhuangshijian:) forControlEvents:UIControlEventTouchUpInside];
//    [view2 addSubview:jiantouBtn3];
//    
//    [_da setAccessibilityLanguage:@"Chinese"];
//    
//    
//    anzhuangTextFied.inputView = _da;
    
    
    
    view6=[[UIView alloc]initWithFrame:CGRectMake(0,0, ScreenWidth, 130)];
    view6.backgroundColor=[UIColor whiteColor];
    view6.layer.borderWidth = 0.35;
    view6.layer.borderColor = qianhuicolor.CGColor;
    
    
    tv=[[UITextView alloc]init];
    tv.frame=CGRectMake(20, 20, ScreenWidth-40, 90);
    tv.backgroundColor = [UIColor whiteColor];//设置它的背景颜色/Users/jiezsoft/Desktop/
    tv.scrollEnabled = YES;//是否可以拖动
    tv.delegate=self;
    tv.font = [UIFont fontWithName:@"Arial" size:15.0];//设置字体名字和字体大小
    tv.layer.borderWidth =0.0;
    CGColorSpaceRef registedSpace11 = CGColorSpaceCreateDeviceRGB();
    CGColorRef tureBTncolorref111 = CGColorCreate(registedSpace11,(CGFloat[]){ 0, 0, 0, 0.3 });
    //tv.keyboardType = UIKeyboardTypePhonePad;
    [tv.layer setBorderColor:tureBTncolorref111];//边框颜色
    tv.layer.cornerRadius =0;
    [view6 addSubview:tv];
    imagess=[[UIImageView alloc]initWithFrame:CGRectMake(0, 5, 51/3, 51/3)];
    imagess.image=[UIImage imageNamed:@"_0000_xingxifankui.png"];
    [tv addSubview:imagess];
    label=[[UILabel alloc]init];
    label.frame =CGRectMake(23, 7, ScreenWidth-60, 15);
    label.text = @"备注";
    label.textColor=zuiqianhuicolor;
    label.numberOfLines=0;
    label.font=[UIFont systemFontOfSize:15];
    label.enabled = NO;//lable必须设置为不可用
    label.backgroundColor = [UIColor clearColor];
    [tv addSubview:label];
    
    tv.inputAccessoryView = myToolBar;
    
    
//    NSUserDefaults *user = [NSUserDefaults standardUserDefaults];
//    NSString* Token = [user objectForKey:@"tokenId"];
//    NSMutableDictionary *param1 = [NSMutableDictionary new];
//    [param1 setValue:Token forKey:@"tokenId"];
//    
//    
//    
//    [HttpRequest requestData:@"Business/Whs/WhsItemList" params:param1 success:^(BOOL isSuccess, SeverData *severDataDict) {
//        if (isSuccess) {
//            if ([[severDataDict.dataDict objectForKey:@"ResultInt"] integerValue]==0) {
//                [Global hideProgressHUDInternal:self.view];
//                arrrss1=[[NSMutableArray alloc]init];
//                
//                arrrss1=[severDataDict.dataDict objectForKey:@"DataLine"];
//                
//                NSLog(@"%@",arrrss1);
//                [leixingBtn1 setTitle:[NSString stringWithFormat:@"                  %@",[arrrss1[0]objectForKey:@"whsName"]] forState:UIControlStateNormal];
//                commdity.content1= [NSString stringWithFormat:@"                  %@",[arrrss1[0]objectForKey:@"whsName"]];
//                commdity.actTypeCode=[arrrss1[0]objectForKey:@"id"];
//                self.whsId=[arrrss1[0]objectForKey:@"id"];
//                codearr = [[NSMutableArray alloc] init];
//                contenarrr = [[NSMutableArray alloc] init];
//                NSMutableArray* arrr=[[NSMutableArray alloc]init];
//                arrr=[severDataDict.dataDict objectForKey:@"DataLine"];
//                for (NSDictionary* dicc in arrr )
//                {
//                    [contenarrr addObject:[dicc valueForKey:@"whsName"]];
//                    
//                    [codearr addObject:[dicc valueForKey:@"id"]];
//                    
//                }
//                
//            }else{
//                [Global hideProgressHUDInternal:self.view];
//                NSString *requestResultStr=[severDataDict.dataDict objectForKey:@"ResultString"];
//                [Global showTextHudSub:requestResultStr view:self.view];
//            }
//            
//        }
//        else
//        {
//            [Global hideProgressHUDInternal:self.view];
//            NSLog(@"aaaaaaaa%@",severDataDict.dataDict);
//            [Global showTextHudSub:@"连接失败" view:self.view];
//        }
//        
//    }];
    [self add];
    
}







-(void)add{
    
    
    dealPrice= [[NSMutableArray alloc] init];
    headImage= [[NSMutableArray alloc] init];
    itemId= [[NSMutableArray alloc] init];
    itemName= [[NSMutableArray alloc] init];
    quantity= [[NSMutableArray alloc] init];
    salePrice= [[NSMutableArray alloc] init];
    specId= [[NSMutableArray alloc] init];
    specName = [[NSMutableArray alloc] init];
    specPrice = [[NSMutableArray alloc] init];
    returnQty= [[NSMutableArray alloc] init];
    porderItemId= [[NSMutableArray alloc] init];
    selectFeatureCodeArray=[[NSMutableArray alloc] init];
    selectimageArray=[[NSMutableArray alloc] init];
    selectshuliangArray=[[NSMutableArray alloc] init];
    selectduoshaoArray=[[NSMutableArray alloc] init];
    itemType=[[NSMutableArray alloc] init];
    porderItemIdArray=[[NSMutableArray alloc] init];
    orderItemIds=[[NSMutableArray alloc] init];
    itemCode=[[NSMutableArray alloc] init];
    deliveryStatus=[[NSMutableArray alloc] init];
    
    selectitemCodeArray=[[NSMutableArray alloc] init];
    keyishopCartIds=[[NSMutableArray alloc] init];
    xiugaishuliangArray=[[NSMutableArray alloc] init];
    keyidealPrice=[[NSMutableArray alloc] init];
    keyiitemCode=[[NSMutableArray alloc] init];
    keyiitemName=[[NSMutableArray alloc] init];
    keyiheadImage=[[NSMutableArray alloc] init];
    keyispecName=[[NSMutableArray alloc] init];
    keyiquantity=[[NSMutableArray alloc] init];
    
    table_list = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, ScreenWidth, ScreenHeight-44) style:UITableViewStylePlain];
    table_list.delegate = self;
    table_list.dataSource = self;
    table_list.separatorStyle=UITableViewCellSeparatorStyleNone;
    [self.view addSubview:table_list];
    table_list .tableHeaderView=view;
    table_list .tableFooterView=view6;
    [sxBtn removeFromSuperview];
    
    sxBtn = [[UIButton alloc] initWithFrame:CGRectMake(30, 0.0, 30, 30)];
    [sxBtn setImage:[UIImage imageNamed:@""] forState:UIControlStateNormal];
    //        [sxBtn addTarget:self action:@selector(saoyisao:) forControlEvents:UIControlEventTouchUpInside];
    UIBarButtonItem* myBtnBtn = [[UIBarButtonItem alloc] initWithCustomView:sxBtn];
    self.navigationItem.rightBarButtonItem = myBtnBtn;
    
    NSUserDefaults *user = [NSUserDefaults standardUserDefaults];
    NSString* Token = [user objectForKey:@"tokenId"];
    if (Token ==nil) {
        Token=@"dd";
    }
    NSMutableDictionary *param = [NSMutableDictionary new];
    [param setValue:Token forKey:@"tokenId"];
    [param setValue:commdity.orderId forKey:@"purchaseId"];
    [Global showIndeterminateHudSub:@"加载中，请稍后。。。" delay:30 view:self.view];
    NSLog(@"-----------%@", param);
    
    [HttpRequest requestData:@"Business/Purchase/Detail" params:param success:^(BOOL isSuccess, SeverData *severDataDict) {
        if (isSuccess) {
            NSLog(@"-----------%@", severDataDict.dataDict);
            if ([[severDataDict.dataDict objectForKey:@"ResultInt"] integerValue]==0) {
                [Global hideProgressHUDInternal:self.view];
                
                
                NSString *s2 =[[severDataDict.dataDict objectForKey:@"purchase"]objectForKey:@"purchaseNo"];
                UIFont *font2 = [UIFont systemFontOfSize:17];
                CGSize size2 = CGSizeMake(ScreenWidth-60, 2000);
                CGSize labelsize2 = [s2 sizeWithFont:font2 constrainedToSize:size2 lineBreakMode:NSLineBreakByCharWrapping];
                
                UILabel* shelfNo=[[UILabel alloc]initWithFrame:CGRectMake(15, 15, labelsize2.width+5, 17)];
                shelfNo.text=[[severDataDict.dataDict objectForKey:@"purchase"]objectForKey:@"purchaseNo"];
                shelfNo.textColor=[UIColor blackColor];
                shelfNo.font=[UIFont systemFontOfSize:17];
                [view1 addSubview:shelfNo];
                
                
                commdity.whsId=[[severDataDict.dataDict objectForKey:@"purchase"]objectForKey:@"whsId"];
                
                commdity.whsName=[[severDataDict.dataDict objectForKey:@"purchase"]objectForKey:@"whsName"];
                
                commdity.supplierId=[[severDataDict.dataDict objectForKey:@"purchase"]objectForKey:@"supplierId"];
                
                commdity.supplier=[[severDataDict.dataDict objectForKey:@"purchase"]objectForKey:@"supName"];
                
                [leixingBtn setTitle:[NSString stringWithFormat:@"            %@",  commdity.supplier] forState:UIControlStateNormal];
                [leixingBtn1 setTitle:[NSString stringWithFormat:@"            %@", commdity.whsName] forState:UIControlStateNormal];
                
                UILabel *line1=[[UILabel alloc] initWithFrame:CGRectMake(0, 70, ScreenWidth, 0.35)];
                line1.backgroundColor=qianhuicolor;
                [view1 addSubview:line1];
                UILabel* duogou=[[UILabel alloc]initWithFrame:CGRectMake(15, 85/2, 40, 15)];
                duogou.text=[NSString stringWithFormat:@"员工"];
                duogou.textColor=zhonghuiColor;
                duogou.font=[UIFont systemFontOfSize:contenfot];
                [view1 addSubview:duogou];
                NSUserDefaults *user1 = [NSUserDefaults standardUserDefaults];
                NSString* UserName = [[severDataDict.dataDict objectForKey:@"purchase"] objectForKey:@"createName"] ;
                
                self.GuideCode = [user1 objectForKey:@"UserCode"];
                daogouname=[[UIButton alloc]initWithFrame:CGRectMake(50, 85/2,80,15)];
                [daogouname setTitle:UserName forState:UIControlStateNormal];
                daogouname.titleLabel.font=[UIFont systemFontOfSize:contenfot];
                //[daogouname addTarget:self action:@selector(xuanzhidaogou:) forControlEvents:UIControlEventTouchUpInside];
                daogouname.contentHorizontalAlignment=UIControlContentHorizontalAlignmentLeft;
                [daogouname setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
                [view1 addSubview:daogouname];
                
                
                
                
                UILabel* orderDate=[[UILabel alloc]initWithFrame:CGRectMake(daogouname.right, 85/2, 35, 15)];
                orderDate.text=@"日期";
                orderDate.textColor=zhonghuiColor;
                orderDate.font=[UIFont systemFontOfSize:contenfot];
                [view1 addSubview:orderDate];
                NSRange range={0,10};
                NSString* string =[[[severDataDict.dataDict objectForKey:@"purchase"] objectForKey:@"createDate"] substringWithRange:range];
                UILabel* orderDate1=[[UILabel alloc]initWithFrame:CGRectMake(orderDate.right, 85/2, 180, 15)];
                orderDate1.text=string;
                orderDate1.textColor=shenhuicolor;
                orderDate1.font=[UIFont systemFontOfSize:contenfot];
                [view1 addSubview:orderDate1];
                
                view3=[[UIView alloc]initWithFrame:CGRectMake(0, view2.bottom+10, ScreenWidth, 45)];
                view3.backgroundColor=[UIColor whiteColor];
                [view addSubview:view3];
                UILabel *lineL=[[UILabel alloc] initWithFrame:CGRectMake(0, 0, ScreenWidth, 0.35)];
                lineL.backgroundColor=qianhuicolor;
                [view3 addSubview:lineL];
                
                UILabel*shangpingxinxi=[[UILabel alloc]initWithFrame:CGRectMake(15, 0, 80, 45)];
                shangpingxinxi.text=@"商品信息";
                shangpingxinxi.textColor=[UIColor blackColor];
                shangpingxinxi.font=[UIFont systemFontOfSize:sixteenORfifteenFot];
                [view3 addSubview:shangpingxinxi];
                
                
                NSNumber*Total = [[severDataDict.dataDict objectForKey:@"purchase"]objectForKey:@"totalMoney"];
                
                
                NSNumberFormatter *numberFormatter = [[NSNumberFormatter alloc] init];
                [numberFormatter setPositiveFormat:@"###,##0.00;"];
                NSString *formattedNumberString = [numberFormatter stringFromNumber:[NSNumber numberWithDouble:Total.doubleValue]];
                weightke=[[UILabel alloc]initWithFrame:CGRectMake(ScreenWidth-250, 0, 230, 45)];
                weightke.text=[NSString  stringWithFormat:@"共 %@ 件   ￥%@",[[severDataDict.dataDict objectForKey:@"purchase"]objectForKey:@"totalQuantity"], formattedNumberString];
                weightke.textColor = [UIColor colorWithRed:5.00/255.0 green:18.0/255.0 blue:40.00/255.0 alpha:1];
                weightke.textAlignment = NSTextAlignmentRight;
                weightke.font = [UIFont systemFontOfSize:16];
                
                
                
                NSMutableAttributedString *AttributedStr2 = [[NSMutableAttributedString alloc]initWithString:[NSString  stringWithFormat:@"共 %@ 件   ￥%@",[[severDataDict.dataDict objectForKey:@"purchase"]objectForKey:@"totalQuantity"], formattedNumberString]];
                [AttributedStr2 addAttribute:NSFontAttributeName
                 
                                       value:[UIFont systemFontOfSize:13.0]
                 
                                       range:NSMakeRange(0, 7)];
                
                [AttributedStr2 addAttribute:NSForegroundColorAttributeName
                 
                                       value:zhonghuiColor
                 
                                       range:NSMakeRange(0, 7)];
                
                
                weightke.attributedText = AttributedStr2;
                [view3 addSubview:weightke];
                
                
                
                UILabel *lineLabel1=[[UILabel alloc] initWithFrame:CGRectMake(15, 45-0.35, ScreenWidth-30, 0.35)];
                lineLabel1.backgroundColor=qianhuicolor;
                [view3 addSubview:lineLabel1];
                
                
                
                
                NSMutableArray* arrr=[[NSMutableArray alloc]init];
                arrr=[severDataDict.dataDict objectForKey:@"purchaseItem"];
                
                if (arrr.count>0) {
                    
                    for (NSDictionary* dicc in arrr )
                    {
                       
                        [headImage addObject:[dicc valueForKey:@"imageUrlFull"]];
                        [itemId addObject:[dicc valueForKey:@"itemId"]];
                        [itemName addObject:[dicc valueForKey:@"itemName"]];
                        [quantity addObject:[dicc valueForKey:@"quantity"]];
                        [porderItemId addObject:[dicc valueForKey:@"purchaseItemId"]];
                        [specId addObject:[dicc valueForKey:@"specId"]];
                        //                            [shopCartIds addObject:[dicc valueForKey:@"id"]];
                        [specName addObject:[dicc valueForKey:@"specName"]];
                        [returnQty addObject:[dicc valueForKey:@"returnQty"]];
                        [itemType addObject:[dicc valueForKey:@"itemType"]];
                        [itemCode addObject:[dicc valueForKey:@"itemCode"]];
                         [dealPrice addObject:[dicc valueForKey:@"purchasePrice"]];
                        [xiugaishuliangArray addObject:@"1"];
                        [deliveryStatus addObject:[dicc valueForKey:@"returnStatus"]];
                        
                        
                    }
                }else{
                    
                    
                    
                    
                }
                
                
                
                
                
                
                
                
                [table_list reloadData];
                [hejibuyBtn1 removeFromSuperview];
                [self heji];
                
                
                UIButton*buyBtn2=[[UIButton alloc]initWithFrame:CGRectMake(ScreenWidth*430/750, ScreenHeight-45, ScreenWidth*320/750, 45)];
                [buyBtn2 setTitle:@"确定" forState:UIControlStateNormal];
                buyBtn2.backgroundColor=luseColor;
                [buyBtn2 addTarget:self action:@selector(shouying:) forControlEvents:UIControlEventTouchUpInside];
                
                [buyBtn2 setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
                [self.view addSubview:buyBtn2];
                
                
                
                
                
                
            }else{
                [Global hideProgressHUDInternal:self.view];
                NSString *requestResultStr=[severDataDict.dataDict objectForKey:@"ResultString"];
                // [Global showTextHud:requestResultStr view:self.view];
                [Global showTextHudSub:requestResultStr view:self.view];
            }
            
        }
        else
        {
            [Global hideProgressHUDInternal:self.view];
            
            [Global showTextHudSub:@"连接失败" view:self.view];
        }
        
    }];
    
    
    
}



#pragma mark - Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return [itemId count];
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"Cell";
    
    shopcatCell* cell = (shopcatCell*)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil)
    {
        NSArray* nib = [[NSBundle mainBundle] loadNibNamed:@"shopcatCell" owner:self options:nil];
        cell = [nib objectAtIndex:0];
    }
    UIButton*jiantou = [[UIButton alloc]init];
    jiantou.frame = CGRectMake(0,0, 8, 13);
    [jiantou setImage:[UIImage imageNamed:@"xiangzuo-.png"] forState:UIControlStateNormal];
    
    //    cell.accessoryView = jiantou;
    
    
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    
    
    cell.saveAccount=YES;
    
    
    [cell.imageview.layer setCornerRadius:5.0];
    [cell.imageview.layer setBorderWidth:0.3];
    [cell.imageview.layer setMasksToBounds:YES];
    CGColorSpaceRef colorSpace2 = CGColorSpaceCreateDeviceRGB();
    CGColorRef colorref2 = CGColorCreate(colorSpace2,(CGFloat[]){ 0, 0, 0, 0.3 });
    [cell.imageview.layer setBorderColor:colorref2];//边框颜色
    [cell.imageview setImageWithURL:[NSURL URLWithString:[headImage objectAtIndex:indexPath.row]] placeholderImage:[UIImage imageNamed:@""]];
    
    
    
    
    cell.title.text =[NSString stringWithFormat:@"%@%@",[itemCode objectAtIndex:indexPath.row],[itemName objectAtIndex:indexPath.row]];
    
    cell.title.font=[UIFont systemFontOfSize:16];
    cell.title.textColor=[UIColor blackColor];
    
    cell.title.numberOfLines=2;
    
    if ([[specName objectAtIndex:indexPath.row]isEqualToString:@""]) {
        cell.guige.text =[NSString stringWithFormat:@"%@",@" "];
    }else{
        cell.guige.text =[NSString stringWithFormat:@"%@",[specName objectAtIndex:indexPath.row]];}
    cell.guige.font=[UIFont systemFontOfSize:15];
    cell.guige.textColor=zhonghuiColor;
    
    
    
    cell.shuliang.text =[NSString stringWithFormat:@"%.f",  [[quantity objectAtIndex:indexPath.row]floatValue]];
    cell.shuliang.font=[UIFont systemFontOfSize:15];
    
    NSString*GoldPrice=[NSString stringWithFormat:@"%@",[dealPrice objectAtIndex:indexPath.row]];
    NSNumberFormatter *numberFormatter = [[NSNumberFormatter alloc] init];
    [numberFormatter setPositiveFormat:@"###,##0.00;"];
    NSString *formattedNumberString = [numberFormatter stringFromNumber:[NSNumber numberWithDouble:GoldPrice.floatValue]];
    cell.jiage.text =[NSString stringWithFormat:@"￥%@",  formattedNumberString];
    cell.jiage.font=[UIFont systemFontOfSize:eighteenthORfifteenFot];
    cell.jiage.textColor=hongsecolor;
    cell.xiugaijiage=[NSString stringWithFormat:@"%@",[dealPrice objectAtIndex:indexPath.row]];
    
    if  ([orderItemIds containsObject:[specId objectAtIndex:indexPath.row]]){
        
        [cell.xuanzeBtn setImage:[UIImage imageNamed:@"gous"] forState:UIControlStateNormal];
        //      cell.xuanzeimage.image=[UIImage imageNamed:@"gous"];
        cell.saveAccount=NO;
        
    }
    cell.xiugai.tag=indexPath.row;
    [cell.xiugai addTarget:self action:@selector(xiugai:) forControlEvents:UIControlEventTouchUpInside];
    if ([[deliveryStatus objectAtIndex:indexPath.row]isEqualToString:@"Y"] ) {
        //        cell.xuanzeimage.image=[UIImage imageNamed:@"huisegou"];
        [cell.xuanzeBtn setImage:[UIImage imageNamed:@"huisegou"] forState:UIControlStateNormal];
        cell.userInteractionEnabled=NO;
        
        
        
    }else{
        
        [cell.xiugai setBackgroundImage :[UIImage imageNamed:@"bianji.png"] forState:UIControlStateNormal];
       
    }
    
    UILabel *shuliang=[[UILabel alloc] initWithFrame:CGRectMake(ScreenWidth-200, 100, 180, 20)];
    shuliang.text=[NSString stringWithFormat:@"已退数量 %@",[returnQty objectAtIndex:indexPath.row]];
    shuliang.textAlignment=NSTextAlignmentRight;
    shuliang.font=[UIFont systemFontOfSize:12];
    shuliang.textColor=shenhuicolor;
    [cell.contentView addSubview:shuliang];
    
    
    cell.shu=[NSString stringWithFormat:@"%@",[xiugaishuliangArray objectAtIndex:indexPath.row]];
    
    
    if (itemId.count !=indexPath.row+1) {
        UILabel *lineLabel31=[[UILabel alloc] initWithFrame:CGRectMake(15, 120-0.35, ScreenWidth-30, 0.35)];
        lineLabel31.backgroundColor=qianhuicolor;
        [cell.contentView addSubview:lineLabel31];
        
    }
    
    if (itemId.count ==indexPath.row+1) {
        UILabel *lineLabel31=[[UILabel alloc] initWithFrame:CGRectMake(0, 120-0.35, ScreenWidth, 0.35)];
        lineLabel31.backgroundColor=qianhuicolor;
        [cell.contentView addSubview:lineLabel31];
        
    }
    
    return cell;
}

- (CGFloat) tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    
    return  120;
}





- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    
    [toumingtu removeFromSuperview];
    [xiugaiview removeFromSuperview];
    
    UITableViewCell *cell=[tableView cellForRowAtIndexPath:indexPath];
    shopcatCell *sharecell=(shopcatCell *)cell;
    sharecell.saveAccount=! sharecell.saveAccount;
    
    if (!sharecell.saveAccount) {
        
        [selectFeatureCodeArray addObject:[NSString stringWithFormat:@"%@",[itemName objectAtIndex:indexPath.row]]];
        [selectimageArray addObject:[headImage objectAtIndex:indexPath.row]];
        [selectshuliangArray addObject:[quantity objectAtIndex:indexPath.row]];
        [selectduoshaoArray addObject:[NSString stringWithFormat:@"%@",[dealPrice objectAtIndex:indexPath.row]]];
        [porderItemIdArray addObject:[porderItemId objectAtIndex:indexPath.row]];
        [selectitemCodeArray addObject:[itemId objectAtIndex:indexPath.row]];
        [orderItemIds addObject:[specId objectAtIndex:indexPath.row]];
        
        UITableViewCell *cell=[tableView cellForRowAtIndexPath:indexPath];
        shopcatCell *sharecell=(shopcatCell *)cell;
        //      sharecell.xuanzeBtn.image=[UIImage imageNamed:@"gous"];
        [sharecell.xuanzeBtn setImage:[UIImage imageNamed:@"gous"] forState:UIControlStateNormal];
        
        
          [self heji];
    }
    else{
        UITableViewCell *cell=[tableView cellForRowAtIndexPath:indexPath];
        shopcatCell *sharecell=(shopcatCell *)cell;
        //      [xuanze setImage:[UIImage imageNamed:@"quans"] forState:UIControlStateNormal];
        //      sharecell.xuanzeBtn.image=[UIImage imageNamed:@"quans"];
        [sharecell.xuanzeBtn setImage:[UIImage imageNamed:@"quans"] forState:UIControlStateNormal];
        if (selectFeatureCodeArray.count>0) {
            
            for (int i=0; i<selectFeatureCodeArray.count; i++) {
                
                NSString *codeStr = [selectFeatureCodeArray objectAtIndex:i];
                if ([codeStr isEqualToString:[NSString stringWithFormat:@"%@",[itemName objectAtIndex:indexPath.row]]] ) {
                    
                    [porderItemIdArray removeObjectAtIndex:i];//从指定索引移除
                    [orderItemIds removeObjectAtIndex:i];//从指定索引移除
                    [selectFeatureCodeArray removeObjectAtIndex:i];//从指定索引移除
                    [selectimageArray removeObjectAtIndex:i];//从指定索引移除
                    [selectshuliangArray removeObjectAtIndex:i];//从指定索引移除
                    [selectduoshaoArray removeObjectAtIndex:i];//从指定索引移除
                    [selectitemCodeArray removeObjectAtIndex:i];//从指定索引移除
                }
            }
            
              [self heji];
        }
    }
    
  
    //    [hejibuyBtn1 setTitle:[NSString stringWithFormat:@"已选商品%ld件",selectFeatureCodeArray.count] forState:UIControlStateNormal];
    
    NSLog(@"--＝＝＝＝＝＝-------%@",selectFeatureCodeArray);
    
}

- (void)textFieldDidBeginEditing:(UITextField *)textField{
    
    [UIView setAnimationCurve:UIViewAnimationCurveEaseOut];
    table_list .frame =CGRectMake(0, -150, ScreenWidth, ScreenHeight);
    [UIView commitAnimations];
    
        
    }

//修改按钮
-(void)xiugai:(UIButton*)sender{
    
    [xiugaiview removeFromSuperview];
    UIButton* button=(UIButton * )sender;
    shopcatCell* cell=(shopcatCell* )button.superview.superview;
    cell.saveAccount=NO;
    if (selectFeatureCodeArray.count>0) {
        
        for (int i=0; i<selectFeatureCodeArray.count; i++) {
            
            NSString *codeStr = [selectFeatureCodeArray objectAtIndex:i];
            if ([codeStr isEqualToString:[NSString stringWithFormat:@"%@",[itemName objectAtIndex:sender.tag]]] ) {
                
                [porderItemIdArray removeObjectAtIndex:i];//从指定索引移除
                [orderItemIds removeObjectAtIndex:i];//从指定索引移除
                [selectFeatureCodeArray removeObjectAtIndex:i];//从指定索引移除
                [selectimageArray removeObjectAtIndex:i];//从指定索引移除
                [selectshuliangArray removeObjectAtIndex:i];//从指定索引移除
                [selectduoshaoArray removeObjectAtIndex:i];//从指定索引移除
                [selectitemCodeArray removeObjectAtIndex:i];//从指定索引移除
            }
        }
        
    }
    
    [selectFeatureCodeArray addObject:[NSString stringWithFormat:@"%@",[itemName objectAtIndex:sender.tag]]];
    [selectimageArray addObject:[headImage objectAtIndex:sender.tag]];
    [selectshuliangArray addObject:[quantity objectAtIndex:sender.tag]];
    [selectduoshaoArray addObject:[NSString stringWithFormat:@"%@",[dealPrice objectAtIndex:sender.tag]]];
    [porderItemIdArray addObject:[porderItemId objectAtIndex:sender.tag]];
    [selectitemCodeArray addObject:[itemId objectAtIndex:sender.tag]];
    [orderItemIds addObject:[specId objectAtIndex:sender.tag]];
    
    
    [cell.xuanzeBtn setImage:[UIImage imageNamed:@"gous"] forState:UIControlStateNormal];
    
    
    
    toumingtu=[[UIView alloc]initWithFrame:CGRectMake(0, 0, ScreenWidth, ScreenHeight)];
    toumingtu.backgroundColor=[UIColor clearColor];
    
    // 手势
    UITapGestureRecognizer *singleFingerOne = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(closeKeyBoad)];
    singleFingerOne.numberOfTouchesRequired = 1; //手指数
    singleFingerOne.numberOfTapsRequired = 1; //tap次数
    singleFingerOne.delegate = self;
    [toumingtu addGestureRecognizer:singleFingerOne];
    [view6 addSubview:toumingtu];
    
    
    xiugaiview=[[UIButton alloc]initWithFrame:CGRectMake(cell.imageview.right+10, 0, ScreenWidth, 120)];
    xiugaiview.backgroundColor=zuiqianhuicolor;
    [cell addSubview:xiugaiview];
    
    UILabel* cjjlabel=[[UILabel alloc]initWithFrame:CGRectMake(15, 30, 50, 16)];
    cjjlabel.text=@"成交价";
    cjjlabel.textColor=shenhuicolor;
    cjjlabel.font=[UIFont systemFontOfSize:16];
    [xiugaiview addSubview:cjjlabel];
    
    
    jiageTextFied=[[UITextField alloc]initWithFrame:CGRectMake(cjjlabel.right+10,  30, 150, 18)];
    
    jiageTextFied.keyboardType = UIKeyboardTypeDecimalPad;
    jiageTextFied.borderStyle = UITextBorderStyleNone;
    jiageTextFied.font = [UIFont systemFontOfSize: contenfot];
    jiageTextFied.textColor=[UIColor blackColor];
    jiageTextFied.autocapitalizationType = UITextAutocapitalizationTypeSentences;
    jiageTextFied.tag=sender.tag;
    [jiageTextFied addTarget:self action:@selector(userNumberLimitTextLength:) forControlEvents:UIControlEventEditingChanged];
    
    jiageTextFied.text=[NSString stringWithFormat:@"%@",[dealPrice objectAtIndex:sender.tag]];
    [jiageTextFied setUserInteractionEnabled:YES];
    jiageTextFied.font=[UIFont systemFontOfSize:18];
    jiageTextFied.delegate = self;
    jiageTextFied.clearButtonMode = UITextFieldViewModeWhileEditing;
    [xiugaiview addSubview:jiageTextFied];
    
    jiageTextFied.inputAccessoryView = myToolBar;
    UILabel* shulianglabel=[[UILabel alloc]initWithFrame:CGRectMake(15, 75, 50, 16)];
    shulianglabel.text=@"数量";
    shulianglabel.textColor=shenhuicolor;
    shulianglabel.font=[UIFont systemFontOfSize:15];
    [xiugaiview addSubview:shulianglabel];
    
    
    UIImageView*shuimageview=[[UIImageView alloc]initWithFrame:CGRectMake(shulianglabel.right+10, 70, 110, 30)];
    shuimageview .image=[UIImage imageNamed:@"tianjias"];
    [xiugaiview addSubview:shuimageview];
    
    shu=[[UILabel alloc]initWithFrame:CGRectMake(0, 0, 110, 30)];
    shu.text=[NSString stringWithFormat:@"%@",  cell.shuliang.text];
    shu.textColor=[UIColor blackColor];
    shu.center=shuimageview.center;
    shu.textAlignment=NSTextAlignmentCenter;
    shu.font=[UIFont systemFontOfSize:15];
    [xiugaiview addSubview:shu];
    
    UIButton*jian=[[UIButton alloc]initWithFrame:CGRectMake(shulianglabel.right+10, 70, 30, 30)];
    [jian addTarget:self action:@selector(jian:) forControlEvents:UIControlEventTouchUpInside];
    jian.tag=sender.tag;
    [xiugaiview addSubview:jian];
    commdity.status=[NSString stringWithFormat:@"%ld",sender.tag];
    UIButton*jia=[[UIButton alloc]initWithFrame:CGRectMake(shulianglabel.right+10+90,70, 30, 30)];
    jia.tag=sender.tag;
    [jia addTarget:self action:@selector(jia:) forControlEvents:UIControlEventTouchUpInside];
    [xiugaiview addSubview:jia];
    [self heji];
}
//修改价格
- (void)userNumberLimitTextLength:(UITextField*)textField
{
    UITextField* button=(UITextField * )textField;
    shopcatCell* cell=(shopcatCell* )button.superview.superview;
    
    
    NSMutableArray *mutableArray = [NSMutableArray arrayWithArray:dealPrice];
    [mutableArray replaceObjectAtIndex:textField.tag withObject:[NSString stringWithFormat:@"%@", jiageTextFied.text]];
    dealPrice = mutableArray;
    
    [self guolu:[NSString stringWithFormat:@"%ld",textField.tag]];

    NSString*GoldPrice=[NSString stringWithFormat:@"%@",jiageTextFied.text];
    NSNumberFormatter *numberFormatter = [[NSNumberFormatter alloc] init];
    [numberFormatter setPositiveFormat:@"###,##0.00;"];
    NSString *formattedNumberString = [numberFormatter stringFromNumber:[NSNumber numberWithDouble:GoldPrice.floatValue]];
    cell.jiage.text =[NSString stringWithFormat:@"￥%@",  formattedNumberString];
    cell.jiage.font=[UIFont systemFontOfSize:eighteenthORfifteenFot];
    cell.jiage.textColor=hongsecolor;
    
}


-(void)xuan:(UIButton*)sender{
    
    
    
}
-(void)jia:(UIButton*)sender{
    
    UIButton* button=(UIButton * )sender;
    shopcatCell* cell=(shopcatCell* )button.superview.superview;
    
    int d;
    d=shu.text.intValue;
    d++;
    NSLog(@"---------%ld",sender.tag);
    
    
    NSMutableArray *mutableArray = [NSMutableArray arrayWithArray:quantity];
    [mutableArray replaceObjectAtIndex:sender.tag withObject:[NSString stringWithFormat:@"%d", d]];
    quantity = mutableArray;
    
    
    cell.shuliang.text=[NSString stringWithFormat:@"%d", d];
      shu.text=[NSString stringWithFormat:@"%d", d];
    [self guolu:[NSString stringWithFormat:@"%ld",sender.tag]];
    
    
    
    
}

-(void)jian:(UIButton*)sender{
    
    UIButton* button=(UIButton * )sender;
    shopcatCell* cell=(shopcatCell* )button.superview.superview;
    
    if ([cell.shuliang.text isEqualToString:@"1"]) {
        [self showAlertMessage:@"数量不能为 0 件！"];
        [self guolu:[NSString stringWithFormat:@"%ld",sender.tag]];
        
    }else{
        
        int d;
        d= shu.text.intValue;
        d--;
        NSLog(@"---------%ld",sender.tag);
        
        NSMutableArray *mutableArray = [NSMutableArray arrayWithArray:quantity];
        [mutableArray replaceObjectAtIndex:sender.tag withObject:[NSString stringWithFormat:@"%d", d]];
        quantity = mutableArray;//now the array has been "updated"
        cell.shuliang.text=[NSString stringWithFormat:@"%d", d];
        shu.text=[NSString stringWithFormat:@"%d", d];

        [self guolu:[NSString stringWithFormat:@"%ld",sender.tag]];
        
        
    }
    
    
}

-(void)heji{
    [hejibuyBtn1 removeFromSuperview];
    
    NSMutableArray*  sum=[[NSMutableArray alloc]init];
    
    for (int i=0; i<selectduoshaoArray.count; i++) {
        
        NSString *typeCode1 = [selectduoshaoArray objectAtIndex:i];
        NSString *isSingle1 = [selectshuliangArray objectAtIndex:i];
        
        [sum addObject:[NSString stringWithFormat:@"%.2f",  [typeCode1 doubleValue]*[isSingle1 doubleValue]]];
        
        
    }
    
    NSNumber *sum11 = [sum valueForKeyPath:@"@sum.floatValue"];
    
    NSString*GoldPrice=[NSString stringWithFormat:@"%@",sum11];
    NSNumberFormatter *numberFormatter = [[NSNumberFormatter alloc] init];
    [numberFormatter setPositiveFormat:@"###,##0.00;"];
    NSString *formattedNumberString = [numberFormatter stringFromNumber:[NSNumber numberWithDouble:GoldPrice.floatValue]];
    
    hejibuyBtn1=[[UIButton alloc]initWithFrame:CGRectMake(0, ScreenHeight-45, ScreenWidth*430/750, 45)];
    [hejibuyBtn1 setTitle:[NSString stringWithFormat:@"   合计 ¥ %@",formattedNumberString] forState:UIControlStateNormal];
    hejibuyBtn1.backgroundColor=[UIColor colorWithRed:0/255.0 green:0/255.0 blue:0/255.0 alpha:1.0];
    [hejibuyBtn1 setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    hejibuyBtn1.alpha=0.8;
    hejibuyBtn1.contentHorizontalAlignment=UIControlContentHorizontalAlignmentFill;
    hejibuyBtn1.contentVerticalAlignment=UIControlContentVerticalAlignmentBottom;
    hejibuyBtn1.titleLabel.font=[UIFont systemFontOfSize:18];
    NSMutableAttributedString *AttributedStr = [[NSMutableAttributedString alloc]initWithString:[NSString stringWithFormat:@"   合计 ¥ %@",formattedNumberString]];
    
    [AttributedStr addAttribute:NSFontAttributeName
     
                          value:[UIFont systemFontOfSize:13]
     
                          range:NSMakeRange(0, 7)];
    
    [AttributedStr addAttribute:NSForegroundColorAttributeName
     
                          value:[UIColor whiteColor]
     
                          range:NSMakeRange(0, 7)];
    
    
    hejibuyBtn1.titleLabel.attributedText = AttributedStr;
    
    UIButton* shuliang=[[UIButton alloc]initWithFrame:CGRectMake(0, 8, ScreenWidth*430/750, 11)];
    NSNumber *sum1 = [selectshuliangArray valueForKeyPath:@"@sum.floatValue"];
    
    [shuliang setTitle:[NSString stringWithFormat:@"   已选商品 %@ 件",sum1] forState:UIControlStateNormal];
    shuliang.backgroundColor=[UIColor colorWithRed:0/255.0 green:0/255.0 blue:0/255.0 alpha:1.0];
    [shuliang setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    shuliang.titleLabel.font=[UIFont systemFontOfSize:11];
    shuliang.contentHorizontalAlignment=UIControlContentHorizontalAlignmentLeft;
    [hejibuyBtn1 addSubview:shuliang];
    
    [self.view addSubview:hejibuyBtn1];
    
    
    
}
-(void)guolu:(NSString*)tag{
    
   
    if (selectFeatureCodeArray.count>0) {
        
        for (int i=0; i<selectFeatureCodeArray.count; i++) {
            
            NSString *codeStr = [selectFeatureCodeArray objectAtIndex:i];
            if ([codeStr isEqualToString:[NSString stringWithFormat:@"%@",[itemName objectAtIndex:tag.intValue]]] ) {
                
                [porderItemIdArray removeObjectAtIndex:i];//从指定索引移除
                [orderItemIds removeObjectAtIndex:i];//从指定索引移除
                [selectFeatureCodeArray removeObjectAtIndex:i];//从指定索引移除
                [selectimageArray removeObjectAtIndex:i];//从指定索引移除
                [selectshuliangArray removeObjectAtIndex:i];//从指定索引移除
                [selectduoshaoArray removeObjectAtIndex:i];//从指定索引移除
                [selectitemCodeArray removeObjectAtIndex:i];//从指定索引移除
            }
        }
        
    }
    
    [selectFeatureCodeArray addObject:[NSString stringWithFormat:@"%@",[itemName objectAtIndex:tag.intValue]]];
    [selectimageArray addObject:[headImage objectAtIndex:tag.intValue]];
    [selectshuliangArray addObject:[quantity objectAtIndex:tag.intValue]];
    [selectduoshaoArray addObject:[NSString stringWithFormat:@"%@",[dealPrice objectAtIndex:tag.intValue]]];
    [porderItemIdArray addObject:[porderItemId objectAtIndex:tag.intValue]];
    [selectitemCodeArray addObject:[itemId objectAtIndex:tag.intValue]];
    [orderItemIds addObject:[specId objectAtIndex:tag.intValue]];
    
    [self heji];
    
}









//采购收货
-(void)shouying:(UIButton *)sender {
    
    
    
    if ([leixingBtn.titleLabel.text length] < 1) {
        [self showAlertMessage:@"请选择供应商！"];
    } else{
        
        
        
        NSUserDefaults *user = [NSUserDefaults standardUserDefaults];
        NSString* Token = [user objectForKey:@"tokenId"];
        if (Token ==nil) {
            Token=@"dd";
        }
        
        NSMutableDictionary *params = [NSMutableDictionary new];
        [params setValue:Token forKey:@"tokenId"];
        [params setValue:commdity.whsId forKey:@"whsId"];
        [params setValue:commdity.supplierId forKey:@"supplierId"];
//        [params setValue:anzhuangTextFied.text forKey:@"deliveryDate"];
        
        
        
        NSMutableArray *mDocumentLine=[NSMutableArray array];
        
        
        for (int i=0; i<orderItemIds.count; i++) {
            
            NSMutableDictionary *dic = [NSMutableDictionary dictionary];
            NSString *itemIdstr = [selectitemCodeArray objectAtIndex:i];
            NSString *quantitystr =[selectshuliangArray objectAtIndex:i];
            NSString *specIdstr = [orderItemIds objectAtIndex:i];
            NSString *purchasePricestr = [selectduoshaoArray objectAtIndex:i];
            
            NSString *porderItemIdstr = [porderItemIdArray objectAtIndex:i];
            [dic setValue:quantitystr forKey:@"quantity"];
            [dic setValue:itemIdstr forKey:@"itemId"];
            [dic setValue:purchasePricestr forKey:@"purchasePrice"];
            [dic setValue:specIdstr forKey:@"specId"];
            [dic setValue:porderItemIdstr forKey:@"purchaseItemId"];
            [mDocumentLine addObject:dic];
            
            
        }
        [params setValue:mDocumentLine  forKey:@"itemList"];
        [params setValue:tv.text  forKey:@"remark"];
        
        NSLog(@"33333333====%@",params);
        
        
        [Global showIndeterminateHudSub:@"加载中，请稍后。。。" delay:30 view:self.view];
        
        
        [HttpRequest requestData:[NSString stringWithFormat:@"Business/%@/Add",@"PurchaseReturn"] params:params success:^(BOOL isSuccess, SeverData *severDataDict) {
            if (isSuccess) {
                NSLog(@"33333333====%@",severDataDict.dataDict);
                if ([[severDataDict.dataDict objectForKey:@"ResultInt"] integerValue]==0) {
                    [Global hideProgressHUDInternal:self.view];
                    
                    NSString *requestResultStr=[severDataDict.dataDict objectForKey:@"ResultString"];
                    [Global showTextHudSub:requestResultStr view:self.view];
                    BusinessPurchaseReturnListViewController *detailViewController = [[BusinessPurchaseReturnListViewController alloc] init];
                    
                    [self.navigationController pushViewController:detailViewController animated:YES];
                    //                    [self.navigationController popToViewController:[self.navigationController.viewControllers objectAtIndex:0] animated:YES];
                    
                }else{
                    [Global hideProgressHUDInternal:self.view];
                    NSString *requestResultStr=[severDataDict.dataDict objectForKey:@"ResultString"];
                    [Global showTextHudSub:requestResultStr view:self.view];
                }
                
            }
            else
            {
                [Global hideProgressHUDInternal:self.view];
                
                [Global showTextHudSub:@"连接失败" view:self.view];
            }
            
        }];
        
    }
}

-(void)xuanzhidaogou1:(UIButton*)sender{
    [anzhuangTextFied resignFirstResponder];
    BusinessWhsWhsItemListViewController *detailViewController = [[BusinessWhsWhsItemListViewController alloc] init];
    detailViewController.codeArray=codearr;
    detailViewController.contentArray=contenarrr;
    [self.navigationController pushViewController:detailViewController animated:YES];
    
    
}



-(void)xuanzhidaogou:(UIButton*)sender{
    
    
    commdity.addhuiyuanViewController=@"选择";
    BusinessSupplierSupplierListViewController *detailViewController = [[BusinessSupplierSupplierListViewController alloc] init];
    [self.navigationController pushViewController:detailViewController animated:YES];
    
}
-(void)closeKeyBoad
{
    [toumingtu removeFromSuperview];
    [xiugaiview removeFromSuperview];
    
    [anzhuangTextFied resignFirstResponder];
    [tv resignFirstResponder];
    [UIView setAnimationCurve:UIViewAnimationCurveEaseOut];
    
    table_list .frame =CGRectMake(0,0, ScreenWidth, ScreenHeight);
    [UIView commitAnimations];
}
-(void)daogouView1:(UIButton *)sender{
    
    
    self.whsId=[[arrrss1 objectAtIndex:sender.tag]objectForKey:@"id"];
    //NSLog(@"%@",self.DocType);
    leixingBtn1.titleLabel.text=sender.titleLabel.text;
    [mainScroll removeFromSuperview];
}

- (BOOL)textViewShouldBeginEditing:(UITextView *)textView{
    
    [UIView setAnimationCurve:UIViewAnimationCurveEaseOut];
    table_list .frame =CGRectMake(0, -200, ScreenWidth, ScreenHeight);
    [UIView commitAnimations];
    
    return self;
}

-(void)textViewDidChange:(UITextView *)textView
{
    //self.examineText =  textView.text;
    
    
    if (textView.text.length == 0) {
        [imagess removeFromSuperview];
        
        imagess=[[UIImageView alloc]initWithFrame:CGRectMake(0, 5, 51/3, 51/3)];
        imagess.image=[UIImage imageNamed:@"_0000_xingxifankui.png"];
        [tv addSubview:imagess];
        label.text = @"备注";
        
    }else{
        [imagess removeFromSuperview];
        label.text = @"";
    }
}

//回收键盘
-(void)OnTapDone{
    [tv resignFirstResponder];
    [jiageTextFied resignFirstResponder];
    
    [self xuan:nil];
    
    [toumingtu removeFromSuperview];
    [xiugaiview removeFromSuperview];
    [UIView setAnimationCurve:UIViewAnimationCurveEaseOut];
    [anzhuangTextFied resignFirstResponder];
    table_list .frame =CGRectMake(0,0, ScreenWidth, ScreenHeight);
    [UIView commitAnimations];
    
}

- (void)showAlertWait
{
    alt = [[UIAlertView alloc] initWithTitle:@"网络不稳定 ！" message:@"请确认网络" delegate:self cancelButtonTitle:nil otherButtonTitles: nil];
    [alt show];
    
    [self performSelector:@selector(hideAlert) withObject:nil afterDelay:1.0f];
    
}

- (void)showAlertMessage:(NSString *)msg
{
    alt = [[UIAlertView alloc] initWithTitle:@"温馨提示" message:msg delegate:nil cancelButtonTitle:nil otherButtonTitles: nil];
    [alt show];
    
    [self performSelector:@selector(hideAlert) withObject:nil afterDelay:1.0f];
}
- (void)hideAlert
{
    if (alt != nil)
    {
        [alt dismissWithClickedButtonIndex:0 animated:YES];
        alt = nil;
    }
}


@end
